// AUSlotsTesterView.cpp : implementation of the CAUSlotsTesterView class
//

#include "stdafx.h"
#include "AUSlotsTester.h"

#include "AUSlotsTesterDoc.h"
#include "AUSlotsTesterView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAUSlotsTesterView

IMPLEMENT_DYNCREATE(CAUSlotsTesterView, CHtmlView)

BEGIN_MESSAGE_MAP(CAUSlotsTesterView, CHtmlView)
	//{{AFX_MSG_MAP(CAUSlotsTesterView)
	ON_COMMAND(ID_TEST_SPIN, OnTestSpin)
	ON_UPDATE_COMMAND_UI(ID_TEST_SPIN, OnUpdateTestSpin)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSave)
	ON_COMMAND(ID_TEST_AUTO_SAVE, OnTestAutoSave)
	ON_UPDATE_COMMAND_UI(ID_TEST_AUTO_SAVE, OnUpdateTestAutoSave)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CHtmlView::OnFilePrint)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAUSlotsTesterView construction/destruction

CAUSlotsTesterView::CAUSlotsTesterView()
{
}

CAUSlotsTesterView::~CAUSlotsTesterView()
{
}

/////////////////////////////////////////////////////////////////////////////
// CAUSlotsTesterView drawing

void CAUSlotsTesterView::OnDraw(CDC* /*pDC*/)
{
	CAUSlotsTesterDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
}

void CAUSlotsTesterView::OnInitialUpdate()
{
	CAUSlotsTesterApp* pApp = (CAUSlotsTesterApp*) AfxGetApp();

	UINT nWebPort = pApp->GetWebPort();

	CString strUrl;

	strUrl.Format( _T("http://127.0.0.1:%lu/%08X/default.html"), nWebPort, GetDocument() );

	Navigate2( strUrl, NULL, NULL );
}

/////////////////////////////////////////////////////////////////////////////
// CAUSlotsTesterView printing


/////////////////////////////////////////////////////////////////////////////
// CAUSlotsTesterView diagnostics

#ifdef _DEBUG
void CAUSlotsTesterView::AssertValid() const
{
	CHtmlView::AssertValid();
}

void CAUSlotsTesterView::Dump(CDumpContext& dc) const
{
	CHtmlView::Dump(dc);
}

CAUSlotsTesterDoc* CAUSlotsTesterView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAUSlotsTesterDoc)));
	return (CAUSlotsTesterDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CAUSlotsTesterView message handlers

void CAUSlotsTesterView::OnTestSpin() 
{
	if ( GetDocument()->IsSpinning() )
	{
		GetDocument()->Spin( false );
	}
	else
	{
		GetDocument()->Spin( true );
	}

	Refresh();
}

void CAUSlotsTesterView::OnUpdateTestSpin(CCmdUI* pCmdUI) 
{
	if ( GetDocument()->IsSpinning() )
	{
		pCmdUI->SetCheck();
	}
	else
	{
		pCmdUI->SetCheck(0);
	}
}

void CAUSlotsTesterView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/) 
{
	Refresh();
}

void CAUSlotsTesterView::OnUpdateFileSave(CCmdUI* pCmdUI) 
{
	if ( GetDocument()->GetSpinState() == CAUSlotsTesterDoc::ssStopped )
	{
		pCmdUI->Enable();
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CAUSlotsTesterView::OnTestAutoSave() 
{
	if ( GetDocument()->IsAutoSaveOn() )
	{
		GetDocument()->SetAutoSave( false );
	}
	else
	{
		GetDocument()->SetAutoSave( true );
	}	
}

void CAUSlotsTesterView::OnUpdateTestAutoSave(CCmdUI* pCmdUI) 
{
	OnUpdateFileSave( pCmdUI );

	if ( GetDocument()->IsAutoSaveOn() )
	{
		pCmdUI->SetCheck();
	}
	else
	{
		pCmdUI->SetCheck(0);
	}
}
